package com.itachi.common.sensitive.enums;

import com.itachi.common.sensitive.utils.DesensitizedUtil;

import java.util.function.Function;

/**
 * 脱敏类型
 */
public enum DesensitizedType {

    USERNAME(s -> s.replaceAll("(\\S)\\S(\\S*)", "$1*$2")), //姓名，第2位星号替换

    PASSWORD(DesensitizedUtil::password), //密码，全部字符都用*代替

    ID_CARD(s -> s.replaceAll("(\\d{4})\\d{10}(\\d{4})", "$1** **** ****$2")), //身份证，中间10位星号替换

    PHONE(s -> s.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")), //手机号，中间4位星号替换

    EMAIL(s -> s.replaceAll("(^.)[^@]*(@.*$)", "$1****$2")), //电子邮箱，仅显示第一个字母和@后面的地址显示，其他星号替换

    BANK_CARD(s -> s.replaceAll("\\d{15}(\\d{3})", "**** **** **** **** $1")), //银行卡号，保留最后4位，其他星号替换

    CAR_LICENSE(DesensitizedUtil::carLicense); //车牌号码，包含普通车辆、新能源车辆

    private final Function<String, String> desensitizer;

    DesensitizedType(Function<String,String> des)
    {
        this.desensitizer = des;
    }

    public Function<String, String> desensitizer()
    {
        return desensitizer;
    }
}
